package com.zerui.manager.feign.handler;

import com.alibaba.cola.exception.BizException;
import com.zerui.manager.feign.DeviceClientFeign;
import com.zerui.manager.feign.request.DeviceActionExecuteRequest;
import com.zerui.manager.feign.response.DeviceEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author wh
 * @create_time 2023-08-23 15:28
 */
@Slf4j
@Component
public class DeviceFeignHandler {

    @Resource
    private DeviceClientFeign deviceClientFeign;
    private static final String CODE = "0000000";

    public String batchActionExecute(List<DeviceActionExecuteRequest> requests) {
        log.info("开始执行物联网接口：" + requests);
        DeviceEntity<Object> body = deviceClientFeign.batchActionExecuteByDeviceId(requests);
	    String code = body.getCode();
	    String message = body.getMessage();
	    Object data = body.getData();
	    if (!CODE.equals(body.getCode())) {
            log.error("远程调用物联网接口/v1/device/actions出错 ：{}", body);
            throw new BizException("设备不支持该操作");
        }
	    log.info("调用物联网关成功  返回数据 code{} message {} data{}",code,message,data);
        return data.toString();
    }

}
